using ThirdLife.UI.WinForms.Controls;

namespace ThirdLife.UI.WinForms.Modules
{
  public class MenuBarUIModule : IUIModule
  {
    private TLMenuBar _menubar;
    private IUIModuleServices _moduleServices;

    #region IUIModule Members

    public IUIModuleServices ModuleServices
    {
      get { return _moduleServices; }
      set { _moduleServices = value; }
    }

    public string Name
    {
      get { return "ThirdLife_MenuBar"; }
    }

    public void Setup()
    {
      _menubar = new TLMenuBar();
      _menubar.SetupView();
      ModuleServices.Startup.ApplicationStarted += Startup_ApplicationStarted;
      ModuleServices.Registration.RequestAddMenu += new System.EventHandler<CustomEventArgument<IMenuDefinition>>(Registration_RequestAddMenu);
      ModuleServices.Registration.RequestAddMenuItem += new System.EventHandler<CustomEventArgument<IMenuItemDefinition>>(Registration_RequestAddMenuItem);
     
    }
     
    void Registration_RequestAddMenuItem(object sender, CustomEventArgument<IMenuItemDefinition> e)
    {
      _menubar.CreateMenuItemFromDefinition(e.Argument);
    }

    void Registration_RequestAddMenu(object sender, CustomEventArgument<IMenuDefinition> e)
    {
      _menubar.CreateMenuFromDefinition(e.Argument);
    }

    #endregion

    private void Startup_ApplicationStarted()
    {
      ModuleServices.Registration.AddToMainScreen(_menubar, new DockLocation(_menubar.Height, 0, true));
    }
  }
}